use rand::{Rng, rng};
use std::cmp::Ordering;
use std::io;
fn main() {
    println!("Guess the number!");
    let upper_limit = 100;
    let lower_limit = 1;

    let secret_number = rng().random_range(lower_limit..upper_limit);
    while (true) {
        let mut guess = String::new();
        println!("Please input your guess.");
        io::stdin()
            .read_line(&mut guess)
            .expect("Failed to read line");
        let guess: i32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(message) => {
                print!("You must enter a number");
                println!("the detailed error message is {}", message);
                continue;
            }
        };
        match guess.cmp(&secret_number) {
            Ordering::Less => {
                println!("Too small!");
            }
            Ordering::Greater => {
                println!("Too big!");
            }
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}
